//
//  TCM_MineHeaderView.swift
//  TCM_TradingProject
//
//  Created by 吕春海 on 2018/8/23.
//  Copyright © 2018年 lvchunhai. All rights reserved.
//

import UIKit

class TCM_MineHeaderView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
    
    var entryNameArr = [String]()
    var entryImageArr = [String]()
    
    @IBOutlet weak var userHeadImageView: UIImageView!
    @IBOutlet weak var mineCollectionView: UICollectionView!
    @IBOutlet weak var certificationLabel: UILabel!
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        mineCollectionView.layer.cornerRadius = 6
        mineCollectionView.clipsToBounds = true
        certificationLabel.layer.cornerRadius = 10.5
        certificationLabel.clipsToBounds = true
        userHeadImageView.layer.cornerRadius = 28
        userHeadImageView.clipsToBounds = true
        
        setCollection()
    }
    
    func setCollection() {
        let layout = UICollectionViewFlowLayout.init()
        layout.itemSize = CGSize.init(width: (TCM_ScreenWidth - 4 - 32 - 5 * 4)/5, height: 82)
        layout.minimumInteritemSpacing = 5
        layout.sectionInset = UIEdgeInsets.init(top: 0, left: 2, bottom: 0, right: 2)
        
        self.mineCollectionView.collectionViewLayout = layout
        
        self.mineCollectionView.delegate = self
        self.mineCollectionView.dataSource = self
        
        self.mineCollectionView!.register(UINib.init(nibName: "TCM_MineCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "entryCell")
    }
    
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 5
    }
    //cellForItemAt indexPath
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = mineCollectionView.dequeueReusableCell(withReuseIdentifier: "entryCell", for: indexPath) as! TCM_MineCollectionViewCell
        cell.entryLabel.text = entryNameArr[indexPath.row]
        cell.entryImageView.image = UIImage.init(named: entryImageArr[indexPath.row])
        return cell
    }
}
